package com.etooling.framework.utils;

import net.sourceforge.pinyin4j.PinyinHelper;

/**
 * Description
 * Create by 彬
 * Date 2022/9/05 15:04
 */
public class StringtoEnUtils {

    public static String  getPinyinHeaderString(String str) {
        //定义一个空字符串去接收
        String convert = "";
        for (int i = 0; i < str.length(); i++) {
            char word = str.charAt(i);
            //提取汉字的首字目
            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
            if (pinyinArray != null) {
                convert += pinyinArray[0].charAt(0);
            }else {
                convert += word;
            }
        }
        return convert.toUpperCase();
    }

    public static String generateSerialNum(Long code, Integer nums) {
        // nums位数字，不够的前面补0
        String format = String.format("%%0%dd", nums);
        // 返回拼接好的编号
        return String.format(format, code);
    }


}